package client;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Rectangle;
import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;

/**
 * @author windsea
 *
 */
public class Client {

    private static JFrame frame = null;
    private JDesktopPane pDesktop = new JDesktopPane();
    Socket client = null;

    public Client() {
        if (frame == null) {
            frame = new JFrame();
        }
        frame.add(pDesktop, BorderLayout.CENTER);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setTitle("Teamviewer Clients");
        frame.setVisible(false);
    }

    public static void setPartnerView(boolean value) {
        if (frame != null) {
            frame.setVisible(true);
            frame.setExtendedState(Frame.MAXIMIZED_BOTH);
        }
    }

    public static void setViewSize(Rectangle rec) {
        int w = (int) ((rec.width) * 0.8);
        int h = (int) ((rec.height) * 0.8);
        frame.setSize(w, h);
        frame.setPreferredSize(new Dimension(w, h));
    }

    public void startC(String ip, int port) {

        try {
            client = new Socket(ip, port);
            setPartnerView(true);
            PartnerHandler partnerHandler = new PartnerHandler(client, pDesktop);
        } catch (UnknownHostException ex) {
        } catch (IOException ex) {
        }
    }
}
